using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace CMSWeb.Content
{
	public class ContentItem
	{
		protected int _contentItemID;
		protected string _text;
		protected string _region;
		protected int _revision;
		protected DateTime? _publishDate;
		protected DateTime _createdDate;

		protected bool _isDirty;

		public ContentItem()
		{
			_contentItemID = 0;
			_text = "";
			_region = "";
			_revision = 0;
			_publishDate = new DateTime?();
			_createdDate = DateTime.Now;
			_isDirty = false;
		}

		public ContentItem(IDataReader reader)
		{

		}

		public int ContentItemID
		{
			get { return _contentItemID; }
		}

		public string Text
		{
			get { return _text; }
			set
			{
				_text = value;
				_isDirty = true;
			}
		}

		public string Region
		{
			get { return _text; }
			set
			{
				_region = value;
				_isDirty = true;
			}
		}

		public int Revision
		{
			get { return _revision; }
			internal set { _revision = value; }
		}

		public DateTime? PublishDate
		{
			get { return _publishDate; }
			set 
			{ 
				_publishDate = value;
				_isDirty = true;
			}
		}

		public DateTime CreatedDate
		{
			get { return _createdDate; }
		}

		public bool IsDirty
		{
			get { return _isDirty; }
		}

		public void Save()
		{
			this._isDirty = false;

			this._revision++;
		}

		public ContentItem GetRevision(int revision)
		{
			if ( revision <= 0 )
				throw new ArgumentOutOfRangeException("revision", "revision must be greater than 0");

			if ( revision == _revision )
				return this;

			return null;

		}
	}
}
